<?php 
require_once 'Captcha/captcha.php'; 

class Utils_Gallerie
{
	private $view = null;
	private $galleries = null;
	
	public function __construct(Zend_View_Interface $view)
	{
		$this->setView($view);
		$this->setGalleries(array());
	}
	
	private function getView()
	{
		return $this->view;
	}
	
	private function setView(Zend_View_Interface $view)
	{
		$this->view = $view;
	}
	
	/**
	 * Retourne les galeries enregistrées
	 *
	 * @return array
	 */
	private function &getGalleries()
	{
		return $this->galleries;
	}
	
	private function setGalleries(array $galleries) {
		$this->galleries = $galleries;
	}
	
	private function getScriptTransition()
	{
		return $this->getView()->serverUrl($this->getView()->baseUrl("/library/transition/jquery.transition-0.2.1.pack.js"));
	}
	
	private function getCssTransition()
	{
		return $this->getView()->serverUrl($this->getView()->baseUrl("/library/transition/default.css"));
	}
	
	private function getScriptGallery(array $paramsGallerie)
	{
		$script = '<script type="text/javascript">
					$(document).ready(function() {
						$(\'#'.$paramsGallerie['id'].'\').transition({';
		unset($paramsGallerie['id']);
		
		foreach ($paramsGallerie as $key => $value) {
			$script .= $key.': '.$value.',
			';
		}
		
		$script .= '});
					});
				</script>
				';
		return $script;
	}
	
	public function isEnabled() {
		return count($this->getGalleries()) != 0;
	}
	
	
	public function getScriptGalleries()
	{
		$script = '';
		foreach ($this->getGalleries() as $gallerie)
		{
			$script .= $this->getScriptGallery($gallerie);
		}
		
		return $script;
	}
	
	public function addGallerie($idGallery, $params = array())
	{
		if (!$this->isEnabled())
		{
			$jquery = $this->getView()->jQuery();
			$jquery->enable();
			$this->getView()->headScript()->appendFile($this->getScriptTransition());
			$this->getView()->headLink()->appendStylesheet($this->getCssTransition());
		}
		$params['id'] = $idGallery;
		array_push($this->getGalleries(), $params);
	}
	
	public function toString()
	{
		return $this->getScriptGalleries();
	}
}